<?php


namespace Core\Helper;

use Logger;

class DatabaseHelper{
    public static function createRestaurantDb($domainCode){
        $code = strtolower(str_replace(array('-'),array('_'), $domainCode ));
        $tmpArr = include (MODULE_PATH.'/Model/config/module.config.php');
        $dbParamArr = $tmpArr['db'];
        $con = mysql_connect($dbParamArr['host'],$dbParamArr['username'],$dbParamArr['password']);
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_query("CREATE DATABASE ".$code,$con);
        mysql_close($con);
        $script = CORE_PATH.'/data/db_script/sample_restaurant.sql';

        $command = "mysql -u ".$dbParamArr['username']." -p".$dbParamArr['password']
            . " -h ".$dbParamArr['host']." -D ".$code." < ".$script;

        Logger::debug($command);
        $output = shell_exec($command);
//        Logger::debug($output);

    }
}